package com.nas.crocus.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nas.crocus.dao.EventoDao;
import com.nas.crocus.domain.Evento;

@Repository
public class EventoDaoImpl implements EventoDao {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    
    @Autowired
    private SessionFactory sessionFactory;
    
    /**
     * {@inheritDoc}
     */
    @Override
    public List<Evento> buscar() {       
        Session session = sessionFactory.getCurrentSession();
        
        return session.createCriteria(Evento.class).list();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Evento buscar(Long eventoId) {
        return (Evento) sessionFactory.getCurrentSession().get(Evento.class,
                eventoId);
    }

    @Override
    public void guardar(Evento evento) {
        sessionFactory.getCurrentSession().save(evento);  
        
    }

    @Override
    public void actualizar(Evento evento) {
        sessionFactory.getCurrentSession().update(evento); 
        sessionFactory.getCurrentSession().flush(); //Para obtener los id de alojamientos nuevos.
    }

    
}
